package binarytree;

import java.util.ArrayList;
import java.util.List;
// Definition for a binary tree node.
class Solution {

    public List<Integer> preOrderList = new ArrayList<>();
    public List<Integer> postOrderList = new ArrayList<>();
    public List<Integer> inOrderList = new ArrayList<>();

    public static void main(String[] args) {
        Solution solution = new Solution();
        TreeNode root;
    }
    public void add(TreeNode root) {

    }
    // 144 先序 中左右
    public List<Integer> preOrderList(TreeNode root) {
        if (root == null) {
            return preOrderList;
        }
        preOrderList.add(root.val);
        if (root.left != null) {
            preOrderList(root.left);
        }
        if (root.right != null) {
            preOrderList(root.right);
        }
        return preOrderList;
    }
    // 145 中序 左中右
    public List<Integer> inorderTraversal(TreeNode root) {
        if (root == null) {
            return inOrderList;
        }
        if (root.left != null) {
            inorderTraversal(root.left);
        }
        inOrderList.add(root.val);
        if (root.right != null) {
            inorderTraversal(root.right);
        }
        return inOrderList;
    }
    // 后序 左右中
    public List<Integer> postorderTraversal(TreeNode root) {
        if (root == null) {
            return postOrderList;
        }
        if (root.left != null) {
            postorderTraversal(root.left);
        }
        if (root.right != null) {
            postorderTraversal(root.right);
        }
        postOrderList.add(root.val);
        return postOrderList;
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
